﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Core;

namespace STCommon.NUnit
{
    public class NUnitPreconditionsFilter : ITestFilter
    {
#region ITestFilter Members

        public bool IsEmpty
        {
            get { return false; }
        }

        public virtual bool Match(ITest test)
        {
            return test.TestType == "TestMethod" &&
                   test.TestName.Name.Contains("Preconditions");
        }

        public bool Pass(ITest test)
        {
            bool passed = Match(test);
            int childIndex = 0;

            while (test.Tests != null && childIndex < test.Tests.Count && !passed)
            {
                passed = Pass(test.Tests[childIndex] as ITest);
                ++childIndex;
            }

            return passed;
        }

#endregion
    }
}
